package com.bdqn.ch03.SL;

import com.bdqn.ch03.mapper.NewsDao;
import com.bdqn.ch03.mapper.impl.NewsDaoImpl;
import com.bdqn.ch03.mapper.impl.NewsDaoMySqlImpl;
import com.bdqn.ch03.mapper.impl.NewsDaoOracleImpl;
import com.bdqn.ch03.mapper.impl.NewsDaoRedisImpl;

/**
 *  创建 NewsDao 实例的工厂
 * 第三章 示例1
 *
 * @aurhor Administrator  whs
 * @since 2024/7/1
 */
public class SimpleDaoFactory {

    /**
     *  创建 NewsDao 实例的工厂方法
     * @return
     */
    public static NewsDao getInstance(){
        return new NewsDaoImpl();
    }
    // 示例4
    public static NewsDao getInstance(String key){
     //    return new NewsDaoImpl();
        switch (key){
            case "mysql":
                return new NewsDaoMySqlImpl();
            case "oracle":
                    return new NewsDaoOracleImpl();
            case "redis":
                return new NewsDaoRedisImpl();
            default: throw new RuntimeException("无效的数据库类型:"+key+", Dao获取失败");
        }
    }
}
